package font;

import java.awt.Graphics;

import main.ErrorException;
import xml.XmlNode;
import define.Config;


public class FontAtlas extends Atlas
{
	public FontAtlas(int size)
	{
		super(size);
	}
		
	protected void drawBlock(Graphics g, RegionAble block) throws ErrorException
	{
		CharInfo info = (CharInfo)block;
		g.setColor(info.m_font.getColor());
		g.setFont(info.m_font.getFont());
		int x = info.m_x;
		if(info.m_font.isWhole())
		{
			x += (info.m_w - info.m_fontW) / 2;
		}
		g.drawString(info.m_char + "", x, info.m_y + info.m_h - info.m_font.getDescent());
	}
	
	protected XmlNode blockToXml(RegionAble block)
	{
		XmlNode node = new XmlNode(Config.FONT_CHAR);
		CharInfo info = (CharInfo)block;
		node.addAttribute(Config.FONT_ATTR_CHAR, info.m_char + "");
		node.addAttribute(Config.FONT_ATTR_X, info.m_x + "");
		node.addAttribute(Config.FONT_ATTR_Y, info.m_y + "");
		node.addAttribute(Config.FONT_ATTR_W, info.m_w + "");
		node.addAttribute(Config.FONT_ATTR_H, info.m_h + "");
		node.addAttribute(Config.FONT_ATTR_ID, info.m_font.getName());
		return node;
	}
}
